<!--  -->
<template>
  <div class="icon">
    <el-popover
      :append-to-body="false"
      id="elpopover"
      name="elpopover"
      ref="elpopover"
      placement="bottom-start"
      width="200"
      trigger="click"
      :popper-class="rotateFlag?'member-popover-rotate':'member-popover'"
    >
      <div class="card" id="card">
        <el-scrollbar style="height:100%">
          <!-- <div class="title">参会人员</div>
          <el-divider></el-divider>-->
          <div class="member" v-for="item in meetUser" :key="item">
            <img src="@/assets/imgs/ic_default_contact_headshot.png" />
            <div class="member-name">{{handleGetUserNameAll(item)}}</div>
          </div>
          <!-- <el-divider v-if="meetUser.length>0"></el-divider> -->
        </el-scrollbar>
      </div>
      <div style="display:flex;float:right" slot="reference">
        <div class="member-item" v-for="(item,index) in meetUser" :key="index" v-show="index<7">
          <img src="@/assets/imgs/ic_default_contact_headshot.png" />
          <div class="member-name">{{handleGetUserName(item)}}</div>
        </div>
        <div class="member-All">
          <div class="circle">
            <i class="el-icon-user-solid" />
            <span>{{meetUser.length}}</span>
          </div>
        </div>
      </div>
    </el-popover>
  </div>
</template>

<script>
import { mapState, mapGetters } from 'vuex'
import { cutString } from '@/utils/util'
import { syncAddress } from '@/api/data.js'
export default {
  name: 'MeetMember',
  props: {
    rotateFlag: Boolean,
  },
  data() {
    return {
      userInfoMap: new Map(),
    }
  },

  components: {},

  computed: {
    ...mapGetters(['meetUser']),
  },

  mounted() {
    this.handleSyncAddress()
  },

  methods: {
    //同步通讯录成员
    handleSyncAddress() {
      const userName = sessionStorage.getItem('userName')
      syncAddress({ tel: userName, did_list: '' }).then((res) => {
        let userInfo = res.data.user_info
        let map = new Map()
        userInfo.forEach((element) => {
          map.set(element.tel, element)
        })
        this.userInfoMap = map
        let obj = {
          name: '我',
        }
        map.set(userName, obj)
      })
    },
    //获得固定长度用户名
    handleGetUserName(tel) {
      let user = this.userInfoMap.get(tel)
      return user ? cutString(user.name, 6, '..') : cutString(tel, 6, '..')
    },
    //获得用户名
    handleGetUserNameAll(tel) {
      let user = this.userInfoMap.get(tel)
      return user ? user.name : tel
    },
    //
    handleRotate(type) {
      // let card = document.getElementById('card')
      // if (type == 90) {
      //   card.style.width = '180px'
      //   card.style.height = '180px'
      //   card.style.transform = 'rotate(90deg)'
      // } else {
      //   card.style.width = '180px'
      //   card.style.height = '300px'
      //   card.style.transform = 'rotate(0deg)'
      // }
      let elpopoverArr = document.getElementsByClassName('member-popover')
      let popover = elpopoverArr[0]
      if (type == 90) {
        popover.style.top = '50px !important'
        popover.style.right = '30px !important'
        popover.style.left = '22'
      } else {
        popover.style.top = '50px '
        popover.style.right = '30px '
      }
    },
  },
}
</script>
<style lang='scss' scoped>
.icon {
  height: 30px;
  width: 50%;
  float: right;
  .member-item {
    float: right;
    padding: 2px 3px 2px 3px;
    img {
      height: 23px;
    }
    .member-name {
      transform: scale(0.8);
      font-size: 10px;
    }
  }
  .member-All {
    float: right;
    padding: 0 3px 0 0;
    .circle {
      margin-top: 5px;
      background-color: #0688ef;
      height: 30px;
      width: 30px;
      border-radius: 100%;
      padding: 7px 2px 8px 4px;
      i {
        font-size: 15px;
      }
      span {
        font-size: 13px;
      }
    }
  }
}
.card {
  height: 200px;
  width: 180px;
  .title {
    text-align: center;
  }
  .member {
    display: flex;
    padding: 1px 0px 2px 0px;
    div {
      margin-left: 4px;
      line-height: 28px;
    }
    img {
      width: 30px;
      height: 30px;
    }
  }
}
::v-deep.el-divider--horizontal {
  display: block;
  height: 1px;
  width: 180px;
  margin: 10px 0;
}
</style>
<style  lang='scss'>
.member-popover {
  background-color: black;
  opacity: 0.9;
  color: white;
}
.member-popover-rotate {
  background-color: black;
  opacity: 0.9;
  color: white;
  top: 50px !important;
  right: 10px !important;
  left: unset !important;
}
.el-scrollbar__wrap {
  overflow-x: hidden;
}
</style>